package de.jonasjelten.jcalc.parser;

import de.jonasjelten.jcalc.exception.JParserException;
import de.jonasjelten.jcalc.mathExps.JDiv;
import de.jonasjelten.jcalc.mathExps.JFac;
import de.jonasjelten.jcalc.mathExps.JFacBounded;
import de.jonasjelten.jcalc.mathExps.JMathExp;
import de.jonasjelten.jcalc.mathExps.JNeg;
import de.jonasjelten.jcalc.mathExps.JSum;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @author Jonas Jelten
 */
public class JBinomeKoefficientParser extends JExpressionParser {
    //( x ) = binome(x;y)
    //( y )
    @Override
    public JMathExp parseExpression(String[] expression) throws JParserException {
        
        if(expression.length != 2) {
            throw new JParserException("The binome function expects two full number arguments.");
        }
        JMathExp aus = parser.doDeepSolve(expression[0], 0);
        JMathExp wieviel = parser.doDeepSolve(expression[1], 0);
        return new JDiv(new JFacBounded(aus, new JSum(aus, new JNeg(wieviel))), new JFac(wieviel));
    }

    @Override
    public List<String> getExpressionAliases() {
        return Arrays.asList(new String[] {"binome", "binomekoefficient"});
    }

}
